// utils/sreach/sreach.wxml.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 获取大类index
        num: -1,
        index: 9,
        arr: [],
        cateId: null,  //小类每一项的Id
        len: 0,
        cateId: -1,
        bigList: [],        //   大类数据

        smallList: [],          //   小类数据

    },
    // 大类二选一事件
    bigChangeBgc: function(e) {
        // console.log(e);
        // console.log(e.currentTarget.dataset.index);
        let that = this;
        that.setData({
            num: e.target.dataset.index
        })
        // console.log(this.data.num)
        that.setData({
            smallList: that.data.bigList[that.data.num].smallCates
        })
    },

    /**
     * 小类多选事件
     */
    smallChangeBgc: function(e) {
        let a = e.currentTarget.dataset.index;
        let smallList = this.data.smallList;
        smallList[a].checked = true,
            this.setData({
                smallList: smallList
            })
        if (smallList[a].checked == true) {
            smallList[a].checked = true;
        } else {
            smallList[a].checked = true;
            console.log(smallList[a].checked)
        }

        this.setData({
            smallList: smallList,
            cateId: e.currentTarget.dataset.id
        })
        console.log(this.data.cateId + "这是点击的几号id")
    },

    //重置事件
    reset: function(e) {
        let that = this;
        that.data.smallList.forEach(item => {
            item.checked = false
        })
        that.setData({
            smallList: that.data.smallList
        })
    },

    /**
     * 选择事件
     */
    secelt: function() {
        let that = this;
        wx.request({
            url: 'https://www.xiaozheng8.com/serviceOrder/findAllGrab/v3',
            method: "post",
            data: {
                userId: wx.getStorageSync("userId"),
                cateId: that.data.cateId
            },
            success: function(res){

                let pages = getCurrentPages();//当前页面栈
                let prevPage = pages[pages.length - 2];//上一页面
                prevPage.setData({
                    //直接给上移页面赋值
                    cateId: that.data.cateId
                });
                wx.navigateBack({
                    detal: -1
                })
                
            }
        })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        let that = this;
        wx.request({
            url: 'https://www.xiaozheng8.com/serviceCate/findAll',
            method: 'post',
            data: {
                userId: wx.getStorageSync("userId"),
                cateId: that.data.cateId
            },
            success: function(res) {
                console.log(res.data.data)
                that.setData({
                    bigList: res.data.data,
                    len: res.data.data.length,
                })

            }
        })
    },




    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})